package com.wx.redis.mq;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.google.common.collect.Lists;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author weixin 2024/11/20 15:35
 */
@Getter
@AllArgsConstructor
public enum BizEnum {

    biz_a_add("biz_a_add", "业务a新建", Lists.newArrayList(TopicMqConstant.topic_a_add)),

    biz_b_add("biz_b_add", "业务b新建", Lists.newArrayList(TopicMqConstant.topic_b_add)),



    ;

    /**
     * 业务操作
     */
    @JsonValue
    private final String biz;

    private final String title;

    // 将主题绑定到业务操作上，多个不同业务订阅者，这里维护多个，不可重复
    private final List<String> topicList;

    /**
     * 判断参数code是否是一个有效的枚举
     */
    public static boolean valid(String biz) {
        return Arrays.stream(values()).anyMatch(anEnum -> anEnum.getBiz().equals(biz));
    }

    /**
     * 获取code对应的枚举
     */
    @JsonCreator
    public static BizEnum of(String biz) {
        return Arrays.stream(values()).filter(anEnum -> anEnum.getBiz().equals(biz)).findFirst().orElse(null);
    }
}
